
function assertReturnStatus() { #params(returnStatus, message)
	if [ $1 -ne 0 ]
	then
		echo $2
		exit 1
	fi
}

origdir=$(dirname $0)

now=`date '+%Y%m%d_%H%M%S'`

basename="EduardElzinJafora-android"

# Always clone to a time related generated folder
dirname="$basename-master-$now"

tag="$1"

if [ $tag ] # tag provided
then
	dirname="$basename-$tag-$now"
fi


#git clone ssh://android@<git location>/EduardElzinJafora-android $dirname
#assertReturnStatus $? "Failed cloning git"

#mkdir $dirname

#cd $dirname

# checkout tag
#if [ $tag ]
#then
#	git checkout $tag -b $tag
#	assertReturnStatus $? "Failed: git checkout $tag -b $tag"
#fi

# build android app
echo Building Android app
#ant clean &> ant-clean.txt
ant clean
assertReturnStatus $? "Failed cleaning android app"
#ant release &> ant.txt
ant release
assertReturnStatus $? "Failed building android app"

apkname=$dirname.apk
cp bin/AndroidProject-release.apk bin/$apkname
assertReturnStatus $? "Failed copying apk to new name"
 
#cd -
echo Building Android app - finished


cd $origdir
